let appid = ''
let directional_url = ''
let scope=''

function login(options) {
	appid = options.appid;
	directional_url = options.directional_url;
	scope=options.scope;
	wechatDirect();
}
// 微信跳转
function wechatDirect() {
	let wechat_url = 'https://open.weixin.qq.com/connect/oauth2/authorize?' +
		'appid=' + appid + '&redirect_uri=' + directional_url +
		'&response_type=code&scope='+scope+'&state=STATE#wechat_redirect'
	console.log(wechat_url, '微信重定向成功');
	window.location = wechat_url;
}

// 处理URL获取code
function getQueryString(name) {
	var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
	var r = window.location.search.substr(1).match(reg);
	if (r != null) {
		return unescape(r[2]);
	}
	return null;
}

export default {
	login,
	getQueryString
}
